Skip to main content

gcd

gcd(dataIn1: number | any[] | Mat, dataIn2: number | any[] | Mat) : number | Mat

param dataIn1 - Note: dataIn1 and dataIn2 must be the same type unless you input a list only. The first input is the first part of the pair of items you want to find the gcd of. This function can find the gcd of two integers, or two 2-D or 1-D Array/Mat objects

param dataIn2 The other part of the pair. Must be identical to the type of dataIn1. It is the item to find the gcd of, whether its two integers, or two matrices, or two lists.

returns: number | Mat - The greatest common divisor is returned as an integer for the cases of 2 integers, or it returns a Mat with the gcd in each indice, element-wise. For example, given two 2x2 matrices, it will find the gcd of a[0][0] and b[0][0] and put it into the return matrix indice result[0][0].


Description

This function is the greatest common divisor function. The greatest common divisor is famous - it is the shared integer between 2 (or more) numbers, such that it divides both of the numbers, and there is no number that can divide them that is larger. I.e. the largest shared divisor.

This function returns the gcd of two integers however, if given lists, it will return the gcd element-wise of each list indice. If given just a list, it will give the gcd of all elements in that list. An example is shown below that may clear this up. For other structures, it also does element-wise computation by index.